package com.schoolvisitors.entity;

import com.schoolvisitors.enums.GenderEnum;
import com.schoolvisitors.enums.UserStatusEnum;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.time.Instant;
import java.time.LocalDateTime;

@Getter
@Setter
@Entity
@Table(name = "users", uniqueConstraints = {
        @UniqueConstraint(name = "username", columnNames = {"wechat_user_id"}),
        @UniqueConstraint(name = "phone", columnNames = {"phone"}),
        @UniqueConstraint(name = "id_number", columnNames = {"id_number"})
})
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Size(max = 255)
    @NotNull
    @Column(name = "wechat_user_id", nullable = false)
    private String wechatUserId;

    @Size(max = 16)
    @NotNull
    @Column(name = "nickname", nullable = false, length = 16)
    private String nickname;

    @Size(max = 5)
    @NotNull
    @Column(name = "real_name", nullable = false, length = 5)
    private String realName;

    @Size(max = 16)
    @NotNull
    @Column(name = "position", nullable = false, length = 16)
    private String position;


    @Size(max = 255)
    @NotNull
    @Column(name = "password", nullable = false)
    private String password;

    @Size(max = 11)
    @NotNull
    @Column(name = "phone", nullable = false, length = 11)
    private String phone;

    @Size(max = 18)
    @NotNull
    @Column(name = "id_number", nullable = false, length = 18)
    private String idNumber;

    @NotNull
    @Column(name = "gender", nullable = false)
    private GenderEnum gender;

    @Column(name = "points", columnDefinition = "int UNSIGNED not null")
    private Long points;

    @NotNull
    @Column(name = "is_active", nullable = false)
    private Boolean isActive = false;

    @NotNull
    @Column(name = "reservation_permission", nullable = false)
    private Boolean reservationPermission = false;

    @NotNull
    @Column(name = "create_at", nullable = false)
    private LocalDateTime createAt;

    @NotNull
    @Column(name = "update_at", nullable = false)
    private LocalDateTime updateAt;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 32)
    private UserStatusEnum status;

}